var app = getApp();
const pathUrl = app.globalData.pathUrl;
Page({
    data: {
      searchInput: '',
      searchValue: '',
      deleteBtnHide: true,
        pathUrl: pathUrl,
        openId: '',
      bpmStatus:'',
        list: [],
      tabBars: [
        // { name: '待领取', bpmStatus:'1' },
        { name: '未安装', bpmStatus: "1" },
        // { name: '进行中', bpmStatus:"10" },
        { name: '已完成', bpmStatus: '10' }
      ],
        pageNumber: 0,
        loading: false, //"上拉加载"的变量，默认false，隐藏  
        loadingComplete: false,  //“没有数据”的变量，默认false，隐藏
    },
    onLoad: function (options) {
        var openId = wx.getStorageSync('openId');
        this.setData({
            openId: openId
        });
        this.onReachBottom();
    },
  //点击搜索按钮
  search: function (e) {
    this.setData({
      searchValue: e.detail.value
    })
    // wx.nextTick(() => {
    //     this.setData({ 
    //         searchValue: ''
    //     })
    // })
    this.ssjg();
  },
  //删除输入框value
  deleteBtn: function () {
    this.setData({
      searchValue: '',
      deleteBtnHide: true
    })
  },
  //监听input value
  searchInputValue: function (e) {
    this.setData({
      searchValue: e.detail.value
    })
    if (e.detail.value != '') {
      this.setData({
        deleteBtnHide: false
      })
    } else {
      this.setData({
        deleteBtnHide: true
      })
    }
  },
  ssjg: function () {
    var that = this;
    that.setData({
      loadingComplete: false, //把“没有数据”设为true，显示  
      loading: false,//把"上拉加载"的变量设为false，隐藏  
      pageNumber: 0,
      list: []
    });
    this.onReachBottom();
  },


    goOrderManagement:function(e){
        var proName = e.currentTarget.dataset.name;
        var bpmStatus = e.currentTarget.dataset.bpmstatus;
        wx.navigateTo({
            url: "/pages/orderManagement/orderManagement?proName=" + proName + '&bpmStatus=' + bpmStatus,
        })
    },
    goPosInstallDetail: function (e) {
        var proNo = e.currentTarget.dataset.prono;
        wx.navigateTo({
            url: "/pages/posInstallDetail/posInstallDetail?proNo=" + proNo
        })
    },
    onReady: function () {

    },
  clickTab: function (e) {
    var that = this;
    if (this.data.bpmStatus === e.currentTarget.dataset.index) {
      return false;
    } else {
      wx.showLoading({
        title: '加载中',
      })
      console.log(e);
      that.setData({
        taskIndex: e.currentTarget.dataset.index,
        bpmStatus: e.currentTarget.dataset.bpmstatus,
        loadingComplete: false, //把“没有数据”设为true，显示  
        loading: false,//把"上拉加载"的变量设为false，隐藏  
        pageNumber: 0,
        list: []
      })


      this.onReachBottom();
    }

  },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        wx.showLoading({
            title: '加载中',
        })
        var that = this;
        that.setData({
            pageHidden: true,
            bpmStatus: '1',
            loadingComplete: false, // 把“没有数据”设为true，显示  
            loading: false, // 把"上拉加载"的变量设为false，隐藏  
            pageNumber: 0,
            list: []
        })
        this.onReachBottom();
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
        wx.showLoading({
            title: '加载中',
        })
        var that = this;
        that.setData({
            loadingComplete: false, //把“没有数据”设为true，显示  
            loading: false,//把"上拉加载"的变量设为false，隐藏  
            pageNumber: 0,
            bpmStatus: '1',
            list: []
        });
        this.onReachBottom();
        wx.stopPullDownRefresh();
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        var that = this;
        var pageNumber = that.data.pageNumber + 1;
        var allList = that.data.list;
        wx.request({
            url: pathUrl + '/rest/posDetailController/list/' + that.data.openId,
            data: {
                posName:that.data.searchValue,
                bpmStatus: that.data.bpmStatus,
                pageNumber: pageNumber,
                pageSize: 10
            },
            success: function (res) {
                if (res.data.ok || res.data.data) {
                    wx.hideLoading()
                    if (res.data.data.length > 0) {
                        allList = allList.concat(res.data.data);
                        if (res.data.data.length < 10) {
                            that.setData({
                                pageNumber: pageNumber,
                                list: allList,
                                loadingComplete: true, //把“没有数据”设为true，显示  
                                loading: false //把"上拉加载"的变量设为false，隐藏  
                            })
                        } else {
                            that.setData({
                                pageNumber: pageNumber,
                                list: allList,
                                loading: true
                            })
                        }
                    } else {
                        wx.hideLoading();
                        that.setData({
                            list: allList,
                            loadingComplete: true, //把“没有数据”设为true，显示  
                            loading: false //把"上拉加载"的变量设为false，隐藏  
                        })
                    }
                } else {
                    wx.showModal({
                        title: '提示',
                        content: '获取数据失败',
                        confirmColor: '#7aa6d1',
                        showCancel: false
                    })
                }
            }
        })
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})